<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var isValid = function(s) {
            if (s.length % 2 == 1) {return false;}
            const stack = [];
            const map = new Map();
            map.set('(', ')');
            map.set('[', ']');
            map.set('{', '}');
            for (let i=0; i<s.length; i++) {
                const c = s[i];
                if (map.has(c)) {
                    stack.push(c);
                } else {
                    const t = stack[stack.length-1];
                    if (map.get(t) === c) {
                        stack.pop();
                    } else {
                        return false;
                    }
                }
            }
            return stack.length === 0;
        };
    </script>
</body>
</html>